package com.dyh.quickdemo.Spy;

import sun.swing.CachedPainter;

import java.util.function.Consumer;

/*
@Author=Joey Wheeler
@Date=2021/4/13 17:49
*/
public class BaseSpy implements Spy {

    Consumer<String> reportUnit;
    StringBuffer stringBuffer;

    public BaseSpy(Consumer<String> reportUnit) {
        this.reportUnit = reportUnit;
        this.stringBuffer = new StringBuffer();
    }

    @Override
    public void addRecord(String msg) {
        stringBuffer.append(msg).append(" ");
    }

    @Override
    public void doReport() {
        reportUnit.accept(stringBuffer.toString());
    }
}
